#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <error.h>
#include <unistd.h>
#include <string.h>

using namespace std;
#define BUFFERSIZE 16

int main(int argc, char * argv[])
{
    int fd = open("./test1.txt", O_RDONLY);
    /*
        SEEK_END 指针位于文件末尾
        SEEK_SET 指针位于文件开头
        SEEK_CUR 指针位于当前位置
    */
    off_t length = lseek(fd, -2, SEEK_END);     //返回值是距离开始的位置
    lseek(fd, 0, SEEK_END);                     //测量文件的大小
    cout << "length:" << length << endl;

    char buffer[BUFFERSIZE] ={0};
    read(fd, buffer, sizeof(buffer));
    cout << "buffer:" << buffer << endl;
}